﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ProgNetComponents.ExtenderProviders.Settings;
using System.ComponentModel;
using System.Drawing.Design;
using ProgNetComponents.Design.Attributes;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using ProgNetComponents.ExtenderProviders;
using ProgNetComponents;
using System.ComponentModel.Design.Serialization;
using ProgNetDxComponents.Design.Editors;
using ProgNetDxComponents.Design.TypeConverters;
using ProgNetDxComponents.ExtenderProviders.Browsers;
using DevExpress.XtraEditors.Controls;

namespace ProgNetDxComponents.ExtenderProviders.Settings
{
    public class BrowserSettings : BaseExtenderSettings
    {
        public BrowserSettings(object owner, BaseExtenderProvider provider)
            : base(owner, provider)
        {
        }
        private string _BrowserName;
        private string _AdditionalBrowserName;
        private string _BrowserDisplayFilter;
        private string _AdditionalBrowserDisplayFilter;
        private LookUpEdit _AdditionalLookup;

        #region Browser
        [Editor(typeof(BrowserNameEditor), typeof(UITypeEditor))]
        [RefreshProperties(System.ComponentModel.RefreshProperties.All)]
        [DynamicBrowsableByType("Owner", typeof(LookUpEdit), typeof(RepositoryItemLookUpEdit))]
        public string BrowserName
        {
            get { return _BrowserName; }
            set
            {
                _BrowserName = value;
                OnSettingsChanged();
                if (value.IsNull())
                {
                    BrowserDisplayFilter = null;
                    Browser = null;
                }
                else
                {
                    Browser = BrowserCache.GetBrowser(value);
                }
            }
        }

        [DynamicHiddenByProperty("BrowserName", null, "")]
        public string BrowserDisplayFilter
        {
            get { return _BrowserDisplayFilter; }
            set
            {
                _BrowserDisplayFilter = value;
                OnSettingsChanged();
            }
        }
        
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public Browser Browser
        {
            get;
            set;
        }
        #endregion
       
        #region AdditionalBrowser
        [DynamicHiddenByProperty("AdditionalBrowserName", "", null)]
        public event ChangingEventHandler AdditionalBrowserValueChanging;

        public void OnAdditionalBrowserValueChanging(object sender, ChangingEventArgs e)
        {
            if (AdditionalBrowserValueChanging != null)
                AdditionalBrowserValueChanging(sender, e);
        }

        [DynamicHiddenByProperty("AdditionalBrowserName", "", null)]
        public event EventHandler AdditionalBrowserValueChanged;

        public void OnAdditionalBrowserValueChanged(object sender)
        {
            if (AdditionalBrowserValueChanged != null)
                AdditionalBrowserValueChanged(sender, EventArgs.Empty);
        }

        [Editor(typeof(BrowserNameEditor), typeof(UITypeEditor))]
        [RefreshProperties(System.ComponentModel.RefreshProperties.All)]
        [DynamicHiddenByType("Owner", typeof(LookUpEdit), typeof(RepositoryItemLookUpEdit))]
        public string AdditionalBrowserName
        {
            get { return _AdditionalBrowserName; }
            set
            {
                _AdditionalBrowserName = value;
                OnSettingsChanged();
                if (value.IsNotNull())
                    AdditionalBrowser = BrowserCache.GetBrowser(value);
                else
                {
                    AdditionalBrowserDisplayFilter = null;
                    AdditionalBrowserPopupKey = System.Windows.Forms.Keys.None;
                    _AdditionalLookup = null;
                }
            }
        }

        [DynamicHiddenByProperty("AdditionalBrowserName", null, "")]
        public string AdditionalBrowserDisplayFilter
        {
            get { return _AdditionalBrowserDisplayFilter; }
            set
            {
                _AdditionalBrowserDisplayFilter = value;
                OnSettingsChanged();
            }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public Browser AdditionalBrowser
        {
            get;
            set;
        }

        [Browsable(false)]
        public LookUpEdit AdditionalLookup
        {
            get { return _AdditionalLookup; }
        }
        #endregion
        
        [DynamicHiddenByProperty("AdditionalBrowserName", null, "")]
        public System.Windows.Forms.Keys AdditionalBrowserPopupKey { get; set; }
    }

   
}
